<template>
    <div class="echarts_box">
        <div id="myChart"></div>
    </div>
</template>

<script setup>
import * as echarts from 'echarts'
import { reactive, onMounted } from "vue"
const state = reactive({
    option: {
        series: [
            {
                name: 'Access From',
                type: 'pie',
                radius: '50%',
                data: [
                    { value: 1048, name: 'Search Engine' },
                    { value: 735, name: 'Direct' },
                    { value: 580, name: 'Email' },
                    { value: 484, name: 'Union Ads' },
                    { value: 300, name: 'Video Ads' }
                ],
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    }
})

onMounted(() => {
    inite_charts()
})

const inite_charts = () => {
    const myChart = echarts.init(document.getElementById('myChart'))
    // 绘制图表
    myChart.setOption(state.option)
    const resizeObserver = new ResizeObserver(() => myChart.resize())
    resizeObserver.observe(document.getElementById('myChart'))
}


</script>

<style scoped lang="less">
.echarts_box {
    width: 100%;
    background-color: @tmb;
    margin-top: .4rem;
    border-radius: @dyj;
    border: @xborder solid @qls;
    box-sizing: border-box;

    #myChart {
        width: 100%;
        height: 4rem;
        display: flex;
        justify-content: center;
        align-items: center;
    }
}
</style>